// WaitingDlg.cpp : implementation file
//

#include "stdafx.h"
#include "WaitingShowDlg.h"
#include "RemoteMapper.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CWaitingDlg dialog

IMPLEMENT_DYNAMIC(CWaitingShowDlg, CDialog)

CWaitingShowDlg::CWaitingShowDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CWaitingShowDlg::IDD, pParent)
{

}

CWaitingShowDlg::~CWaitingShowDlg()
{
}

void CWaitingShowDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
//	DDX_Control(pDX, IDC_STATIC_WAITLABEL, m_infoLabel);
//	DDX_Control(pDX, IDC_ANIMATE_WAITING, m_animWaiting);
}


BEGIN_MESSAGE_MAP(CWaitingShowDlg, CDialog)
	ON_WM_PAINT()
//	ON_WM_LBUTTONDOWN()
ON_WM_CREATE()
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()


// CWaitingDlg message handlers

BOOL CWaitingShowDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// TODO:  Add extra initialization here
	CWnd* pParent = GetParent();
	m_picBackground.Load( IDR_PNG_BACKWAITING, _T("PNG") );
	if ( !pParent )
	{
		CRect rc;
		GetClientRect( &rc );
		// Move window
		ClientToScreen( &rc );
		MoveWindow( rc.left, rc.top, m_picBackground.getWidth(), m_picBackground.getHeight() );
	}
	else
	{
		CRect rcParent, rcClient;
		GetClientRect( rcClient );
		pParent->GetClientRect( &rcParent );
		int x, y;
		x = (rcParent.Width() - m_picBackground.getWidth()) / 2;
		y = (rcParent.Height() - m_picBackground.getHeight()) / 2;
		CPoint startp(x, y);
		ClientToScreen( &startp );
		MoveWindow( startp.x, startp.y, m_picBackground.getWidth(), m_picBackground.getHeight() );
	}

	CRect rcWnd;
	GetClientRect( &rcWnd );
	// width 200, height 30, center
	const int RWIDTH = 200;
	const int RHEIGHT = 30;
	m_infoLabel.MoveWindow( (rcWnd.Width() - RWIDTH) >> 1, (rcWnd.Height() - RHEIGHT) >> 1
		, RWIDTH, RHEIGHT );

	// prepare code page
	LCID curLcid = GetThreadLocale();
	const CRemoteMapperApp::TLocaleMap& rlcMap = static_cast<CRemoteMapperApp*>( AfxGetApp() )->getLocaleMap();
	CRemoteMapperApp::TLocaleMap::const_iterator citr = rlcMap.find( curLcid );
	UINT nCodePage = CP_ACP;
	if ( citr != rlcMap.end() )
	{
		nCodePage = (*citr).second;
	}
	else
	{
		nCodePage = 936;
	}

	CStringW strLabel;
	strLabel.LoadString( IDS_STRING_WAITING );
	// set string property
	m_infoLabel.setLabelString( strLabel );
	m_infoLabel.setFontSize( 16 );
	m_infoLabel.setFontFamily( CTextStatic::E_CHINESE_STXIHEI_FONT );
	m_infoLabel.setCodePage( nCodePage );
	m_infoLabel.setAlignment( CTextStatic::E_ALIGNMENT_CENTER );

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CWaitingShowDlg::OnPaint()
{
	CPaintDC dc(this); // device context for painting
	// TODO: Add your message handler code here
	// Do not call CDialog::OnPaint() for painting messages
	CRect rc;
	GetClientRect( &rc );

	m_picBackground.Show( &dc, rc );
}

void CWaitingShowDlg::OnCancel()
{
	// TODO: Add your specialized code here and/or call the base class

//	CDialog::OnCancel();
}

void CWaitingShowDlg::OnOK()
{
	// TODO: Add your specialized code here and/or call the base class

//	CDialog::OnOK();
}

int CWaitingShowDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO:  Add your specialized creation code here
	CRect rcWnd;
	GetClientRect( &rcWnd );

	m_infoLabel.Create( _T("LABEL"), WS_CHILD | WS_VISIBLE | SS_OWNERDRAW, rcWnd, this );
	return 0;
}

BOOL CWaitingShowDlg::OnEraseBkgnd(CDC* pDC)
{
	// TODO: Add your message handler code here and/or call default

	return TRUE;
	return CDialog::OnEraseBkgnd(pDC);
}
